#ifndef __PARAM_H__
#define __PARAM_H__

#ifdef __cplusplus
extern "C" {
#endif

#include <stdint.h>
#include <stdbool.h>
#define RADAR_EMPTY_ENTER_THRESHOLD 580
#define RADAR_EMPTY_EXIT_THRESHOLD 300
#define RADAR_DIST_THRESHOLD 30
#define RADAR_DIST_COVER 20
#define RADAR_STABLE_THRESHOLD 15

/*当前参数版本，版本不同则所有参数都会回复到默认参数*/
#define PARAM_VALUE_VER 4
#define PARAM_FILE_NAME "param.dat"
#define PARAM_ADV_VALUE_VER 1
#define PARAM_ADV_FILE_NAME "param_adv.dat"
#define DEFAULT_NTP_SERVER "ntp.aliyun.com"
/*产品类型，是高杆还是矮杆*/
typedef enum product_type {
  PRODUCT_TYPE_HIGH,
  PRODUCT_TYPE_SHORT
} ProductType_e;

/*参数列表*/
typedef struct ParamValueV1_ {
  uint8_t radar_sensitivity;            /*雷达触发灵敏度, 0~100*/
  uint8_t radar_fault_thresh;           /*雷达错误门限，0~100*/
  uint32_t radar_trig_interval;         /*雷达触发间隔，单位s*/
  uint8_t pro_type;                     /*产品类型，参考ProductType_e*/
  uint8_t solar_batt_valid;             /*是否具有太阳能电池板*/
  uint32_t timing_pic_interval;         /*秒图间隔，单位s*/
  uint8_t timing_pic_empty_en;          /*无车秒图开关，0关闭，1打开*/
  uint32_t heart_interval;              /*心跳超时间隔，单位s*/
  uint8_t batt_door_alarm_en;           /*电池门报警使能*/
  uint32_t batt_door_alarm_interval;    /*电池报警间隔，单位s*/
  uint8_t batt_low_thresh;              /*低电量报警门限，单位电池容量百分比*/
  uint32_t batt_low_alarm_interval;     /*低电量报警间隔，单位s*/
  uint32_t parking_stable_interval;     /*停稳和空场超时间隔，单位s*/
  uint8_t power_soc_disable;            /*调试模式，1使能，0关闭*/
  uint8_t watchdog_enable;              /*看门狗是否使能*/
  uint32_t watchdog_timeout;            /*看门狗超时时间，单位s*/
  uint16_t radar_cover_dist;            /*雷达遮挡距离阈值，单位cm*/
  uint16_t radar_enter_dist;            /*雷达驶入阈值，单位cm*/
  uint16_t radar_exit_dist;             /*车辆空场距离阈值，单位cm*/
  uint16_t radar_change_dist;           /*雷达阈值变化阈值，单位cm*/
  uint16_t radar_stable_dist_thresh;    /*雷达停稳阈值，单位cm*/
  uint32_t wakeup_interval;             /*MCU唤醒间隔，单位s*/
  uint8_t factory_mode;                 /*工厂模式，0关闭，1打开*/
  uint32_t batt_protect_thresh;         /*电量保护阈值，单位电池容量百分比*/
  uint8_t batt_low_alarm_en;            /*电量低报警使能*/
  uint8_t radar_fault_alarm_en;         /*雷达错误使能*/
  uint32_t radar_fault_alarm_interval;  /*雷达错误报警间隔, */
  uint8_t resevered[2];                 /*保留参数*/
}  __attribute__((aligned(4))) ParamValueV1_t;

typedef struct ParamInfo_ {
  uint8_t version;
  ParamValueV1_t info;
}  __attribute__((aligned(4))) ParamInfo_t;

typedef struct SnapshotParam_ {
  uint8_t time_begin[4];
  uint8_t time_end[4];
  uint32_t interval;
  uint32_t empty_snapshot_en;
}  __attribute__((aligned(4))) SnapshotParam_t;

typedef struct DetectParam_ {
  uint8_t time_begin[4];
  uint8_t time_end[4];
  uint32_t interval;
}  __attribute__((aligned(4))) DetectParam_t;

typedef struct ParamAdvValue_ {
  char ntp_server[64];
  uint32_t first_snapshot_interval;
  SnapshotParam_t snapshot_param[3];
  DetectParam_t detect_param[3];
  uint32_t plate_event_interval;          //车牌停稳时间间隔，默认120s
  uint32_t parking_out_interval;          //遮挡事件过滤间隔，也是出场超时间隔，默认120s
  uint8_t resevered[96];
} __attribute__((aligned(4))) ParamAdvValue_t;

typedef struct ParamAdvInfo_ {
  uint8_t version;
  ParamAdvValue_t info;
}  __attribute__((aligned(4)))ParamAdvInfo_t;


int Param_Init();
int Param_Read(ParamInfo_t *param);
int Param_Write(ParamInfo_t *param);
int Param_Save();
int Param_SetAsDefault();
int Param_AdvRead(ParamAdvInfo_t *param);
int Param_AdvWrite(ParamAdvInfo_t *param);

bool Param_IsDebugMode(ParamInfo_t *p);
void Param_SetDebugMode(ParamInfo_t *p, bool on);
bool Param_IsFactoryMode(ParamInfo_t *p);
void Param_SetFactoryMode(ParamInfo_t *p, bool on);

#ifdef __cplusplus
}
#endif

#endif